local qianliu = fk.CreateSkill {
  name = "qianliu",
}

Fk:loadTranslationTable{
  ["qianliu"] = "潜流",
  [":qianliu"] = "与你距离1以内的角色成为【杀】的目标后，你可以观看牌堆底四张牌，以任意顺序置于牌堆顶或牌堆底；若花色各不相同，"..
  "你可以展示并获得这些牌。",

  ["#qianliu-prey"] = "潜流：你可以展示并获得这些牌",
}

qianliu:addEffect(fk.TargetConfirmed, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(qianliu.name) and data.card.trueName == "slash" and
      target:distanceTo(player) <= 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --room:askToGuanxing(player, {cards = room:getNCards(4, "bottom")})
    local cards = room:getNCards(4, "bottom")
    if not table.find(cards, function (id)
      return table.find(cards, function (id2)
        return id ~= id2 and Fk:getCardById(id):compareSuitWith(Fk:getCardById(id2))
      end) ~= nil
    end) and
      room:askToSkillInvoke(player, {
        skill_name = qianliu.name,
        prompt = "#qianliu-prey",
      }) then
      room:showCards(cards)
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, qianliu.name, nil, true, player)
      return
    end

    local dat = {
      prompt = qianliu.name,
      is_free = true,
      cards = { {}, cards },
      min_top_cards = 0,
      max_top_cards = 4,
      min_bottom_cards = 0,
      max_bottom_cards = 4,
      top_area_name = "Top",
      bottom_area_name = "Bottom",
    }

    local req = Request:new(player, "AskForGuanxing")
    req.focus_text = qianliu.name
    req:setData(player, dat)
    local result = req:getResult(player)
    local top, bottom
    if result ~= "" then
      local d = result
      top = d[1]
      bottom = d[2] or Util.DummyTable
    else
      top = {}
      bottom = cards
    end
    for i = #top, 1, -1 do
      table.removeOne(room.draw_pile, top[i])
      table.insert(room.draw_pile, 1, top[i])
    end
    for i = 1, #bottom, 1 do
      table.removeOne(room.draw_pile, bottom[i])
      table.insert(room.draw_pile, bottom[i])
    end

    room:syncDrawPile()
    room:sendLog{
      type = "#GuanxingResult",
      from = player.id,
      arg = #top,
      arg2 = #bottom,
    }
  end,
})

return qianliu
